package logic

import (
	"context"
	"wechats/wechatrpc/wechatrpc"

	"wechats/api/internal/svc"
	"wechats/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ResisterLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewResisterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ResisterLogic {
	return &ResisterLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ResisterLogic) Resister(req *types.ResisterRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	register, err := l.svcCtx.WechatRpc.Register(l.ctx, &wechatrpc.RegisterRequest{
		Mobile:   req.Mobile,
		Password: req.Password,
		Image:    req.Image,
		Nickname: req.Nickname,
		Address:  req.Address,
		SmsCode:  req.SmsCode,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	} else {

		return &types.Response{
			Message: "注册成功",
			Code:    200,
			Data:    register,
		}, nil
	}

}
